<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>xmake</title>
  <link rel="icon" href="/assets/img/favicon.ico">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="description" content="Description">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
  <style>
	.markdown-body {
		box-sizing: border-box;
		min-width: 200px;
		max-width: 980px;
		margin: 0 auto;
		padding: 45px;
	}

	@media (max-width: 767px) {
		.markdown-body {
			padding: 15px;
		}
	}
  </style>
</head>
<body>
<article class="markdown-body">
<h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/plugin/more_plugins">https://xmake.io/#/plugin/more_plugins</a>
<div id="wwads-panel" class="wwads-cn wwads-vertical wwads-sticky" data-id="239" style="max-width:180px;bottom:20px;right:20px;width:200px;height:260px;background:#fff;position:fixed"></div>
</br>
    <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
<style>
#carbonads {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

#carbonads {
  display: flex;
  max-width: 330px;
  background-color: hsl(0, 0%, 98%);
  box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
}

#carbonads a {
  color: inherit;
  text-decoration: none;
}

#carbonads a:hover {
  color: inherit;
}

#carbonads span {
  position: relative;
  display: block;
  overflow: hidden;
}

#carbonads .carbon-wrap {
  display: flex;
}

.carbon-img {
  display: block;
  margin: 0;
  line-height: 1;
}

.carbon-img img {
  display: block;
}

.carbon-text {
  font-size: 13px;
  padding: 10px;
  line-height: 1.5;
  text-align: left;
}

.carbon-poweredby {
  display: block;
  padding: 8px 10px;
  background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  font-size: 9px;
  line-height: 1;
}
</style>
    <h2 id="vscodeplugin">VSCode Plugin</h2>
<ul>
<li><a href="https://github.com/xmake-io/xmake-vscode">xmake-vscode</a></li>
</ul>
<p><img src="https://raw.githubusercontent.com/xmake-io/xmake-vscode/master/res/problem.gif" width="650px" /></p>
<p><a href="https://code.visualstudio.com/">VSCode</a>is a commonly used text editor, and xmake provides plug-ins&#39; support.</p>
<h3 id="plugininstallation">Plugin installation</h3>
<p>Since VSCode itself only provides text editing functions, we need to install plug-ins to support configuration, compilation, debugging, intellisenses and other functions:</p>
<ul>
<li>XMake</li>
<li>C/C++</li>
<li>CodeLLDB</li>
</ul>
<p>After completing the installation of the plug-in, restart VSCode to see the status bar below:</p>
<p><img src="/assets/img/guide/vscode_status_bar.png" alt=""></p>
<p>You can set the platform, architecture, compilation mode, tool-chain and other options in the status bar, and then click Build to start the build.</p>
<h3 id="customoptions">Custom options</h3>
<p>If these options are not enough, you can create .vscode/settings.json and write the settings required by xmake, such as:</p>
<pre><code>{
...
  "xmake.additionalConfigArguments": [
    "--my_option=true"
  ],
...
}
</code></pre><p>Other xmake options can also be setted in settings.json. After modification, the configuration can be refreshed through the >XMake: Configure command.</p>
<h3 id="configureintellsence">Configure Intellsence</h3>
<p>For a better C++ syntax prompt experience, xmake provides support for <a href="https://microsoft.github.io/language-server-protocol/">Language Server Protocol</a> (LSP for short).</p>
<p>In vscode, we can provide intellsence support by using vscode-cpptools or clangd.</p>
<p>In addition, in order to support intellsence, xmake provides compile_commands.json generation support.</p>
<h4 id="generatecompile_commands">generate compile_commands</h4>
<h5 id="automatictriggergeneration">Automatic trigger generation</h5>
<p>Usually after modifying xmake.lua and clicking Save, the xmake-vscode plugin will trigger the automatic generation of compile_commands.json, which is stored in the .vscode directory by default.</p>
<p>This is also the recommended way. Usually after installing the xmake-vscode plug-in and opening the project with xmake.lua, you only need to edit xmake.lua to save and trigger without any other additional operations.</p>
<h5 id="manuallytriggergeneration">Manually trigger generation</h5>
<p>Of course, if we don’t see the file being generated, we can also use the <code>>XMake: UpdateIntellisense</code> command to manually trigger the generation of .vscode/compile_commands.json in vscode.</p>
<h5 id="configurexmakeluatogenerateautomatically">Configure xmake.lua to generate automatically</h5>
<p>Alternatively, we can also use this rule to automatically update and generate compile_commandss.json</p>
<pre><code class="lang-lua">add_rules("plugin.compile_commands.autoupdate", {outputdir = ".vscode"})
target("test")
     set_kind("binary")
     add_files("src/*.c")
</code></pre>
<p>This will automatically update this file after each build.</p>
<h5 id="manualexecutioncommandgeneration">Manual execution command generation</h5>
<p>If the above methods are invalid, we can also execute the command to generate.</p>
<pre><code class="lang-console">$ xmake project -k compile_commands .vscode
</code></pre>
<h4 id="vscodecpptools">vscode-cpptools</h4>
<p>If we use the vscode-cpptools plug-in to provide intellsence support, we need to go to the vscode plug-in market first, search for C++, the default first plug-in is to install it.</p>
<p>When installed, this plugin provides intellsence and debugging support.</p>
<p>Then, we need to configure the c_cpp_properties.json file and associate it with the <code>.vscode/compile_commands.json</code> we generated.</p>
<pre><code>{
   "env": {
     "myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
     "myCompilerPath": "/usr/local/bin/gcc-7"
   },
   "configurations": [
     {
       "name": "Mac",
       "intelliSenseMode": "clang-x64",
       "includePath": ["${myDefaultIncludePath}", "/another/path"],
       "macFrameworkPath": ["/System/Library/Frameworks"],
       "defines": ["FOO", "BAR=100"],
       "forcedInclude": ["${workspaceFolder}/include/config.h"],
       "compilerPath": "/usr/bin/clang",
       "cStandard": "c11",
       "cppStandard": "c++17",
       "compileCommands": "/path/to/compile_commands.json",
       "browse": {
         "path": ["${workspaceFolder}"],
         "limitSymbolsToIncludedHeaders": true,
         "databaseFilename": ""
       }
     }
   ],
   "version": 4
}
</code></pre><p>That is the <code>"compileCommands": "/path/to/compile_commands.json"</code> configuration item above.</p>
<p>For how to open this configuration file, and more configuration instructions, see:</p>
<ul>
<li><a href="https://code.visualstudio.com/docs/cpp/configure-intellisense-crosscompilation">https://code.visualstudio.com/docs/cpp/configure-intellisense-crosscompilation</a></li>
<li><a href="https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference">https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference</a></li>
</ul>
<p>Of course, in theory, the xmake-vscode plugin can automatically associate and set this file, but considering that users do not necessarily use cpptools, they may also use clangd.</p>
<p>Therefore, the default automatic configuration is not very good, and the author has no time and energy to improve it.</p>
<h4 id="clangd">clangd</h4>
<p>When using clangd, there may be conflicts with the C/C++ plug-in, you can add settings in .vscode/settings.json:</p>
<pre><code>{
  "C_Cpp.codeAnalysis.runAutomatically": false,
  "C_Cpp.intelliSenseEngine": "Disabled",
  "C_Cpp.formatting": "Disabled",
  "C_Cpp.autoAddFileAssociations": false,
  "C_Cpp.autocompleteAddParentheses": false,
  "C_Cpp.autocomplete": "Disabled",
  "C_Cpp.errorSquiggles": "Disabled",
...
}
</code></pre><p>Also, since the compile_commands.json generated by XMake is in the .vscode directory, you need to set the clangd parameter to look for it in the correct location:</p>
<pre><code>{
  "clangd.arguments": [
    "--compile-commands-dir=.vscode",
...
  ]
...
}
</code></pre><h2 id="sublimeplugin">Sublime Plugin</h2>
<ul>
<li><a href="https://github.com/xmake-io/xmake-sublime">xmake-sublime</a></li>
</ul>
<p><img src="https://raw.githubusercontent.com/xmake-io/xmake-sublime/master/res/problem.gif" width="650px" /></p>
<h2 id="intellijideaclionpluin">Intellij IDEA/Clion Pluin</h2>
<ul>
<li><a href="https://github.com/xmake-io/xmake-idea">xmake-idea</a></li>
</ul>
<p><img src="https://raw.githubusercontent.com/xmake-io/xmake-idea/master/res/problem.gif" width="650px" /></p>
<h2 id="vimplugin">Vim Plugin</h2>
<ul>
<li><a href="https://github.com/luzhlon/xmake.vim">xmake.vim</a> (third-party, thanks <a href="https://github.com/luzhlon">@luzhlon</a>)</li>
</ul>
<h2 id="neovimplugin">Neovim Plugin</h2>
<ul>
<li><a href="https://github.com/Mythos-404/xmake.nvim">xmake.nvim</a> (third-party, thanks <a href="https://github.com/Mythos-404">@Mythos_404</a>)</li>
</ul>
<p>The plugin provides easy-to-use configuration UI and auto-generation of <em>compile_commands.json</em> files</p>
<p><img src="https://raw.githubusercontent.com/Mythos-404/xmake.nvim/main/assets/XmakePreview.gif" width="650px" /></p>
<h2 id="gradlepluginjni">Gradle Plugin (JNI)</h2>
<ul>
<li><a href="https://github.com/xmake-io/xmake-gradle">xmake-gradle</a>: A gradle plugin that integrates xmake seamlessly</li>
</ul>
<h3 id="pluginsdsl">plugins DSL</h3>
<pre><code>plugins {
  id &#39;org.tboox.gradle-xmake-plugin&#39; version &#39;1.0.9&#39;
}
</code></pre><h3 id="legacypluginapplication">Legacy plugin application</h3>
<pre><code>buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath &#39;org.tboox:gradle-xmake-plugin:1.0.9&#39;
  }
  repositories {
    mavenCentral()
  }
}

apply plugin: "org.tboox.gradle-xmake-plugin"
</code></pre><h3 id="simplestexample">Simplest Example</h3>
<p>We add <code>xmake.lua</code> to <code>projectdir/jni/xmake.lua</code> and enable xmake in build.gradle.</p>
<h4 id="buildgradle">build.gradle</h4>
<pre><code>android {
    externalNativeBuild {
        xmake {
            path "jni/xmake.lua"
        }
    }
}
</code></pre><h4 id="jni">JNI</h4>
<p>The JNI project structure:</p>
<pre><code>projectdir
  - src
    - main
      - java
  - jni
    - xmake.lua
    - *.cpp
</code></pre><p>xmake.lua:</p>
<pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
target("nativelib")
    set_kind("shared")
    add_files("nativelib.cc")
</code></pre>
<h3 id="moregradleconfiguations">More Gradle Configuations</h3>
<pre><code>android {
    defaultConfig {
        externalNativeBuild {
            xmake {
                // append the global cflags (optional)
                cFlags "-DTEST"

                // append the global cppflags (optional)
                cppFlags "-DTEST", "-DTEST2"

                // switch the build mode to `debug` for `xmake f -m debug` (optional)
                buildMode "debug"

                // set abi filters (optional), e.g. armeabi, armeabi-v7a, arm64-v8a, x86, x86_64
                // we can also get abiFilters from defaultConfig.ndk.abiFilters
                abiFilters "armeabi-v7a", "arm64-v8a"
            }
        }
    }

    externalNativeBuild {
        xmake {
            // enable xmake and set xmake.lua project file path
            path "jni/xmake.lua"

            // enable verbose output (optional), e.g. verbose, warning, normal
            logLevel "verbose"

            // set c++stl (optional), e.g. c++_static/c++_shared, gnustl_static/gnustl_shared, stlport_static/stlport_shared
            stl "c++_shared"

            // set the given xmake program path (optional)
            // program /usr/local/bin/xmake

            // disable stdc++ library (optional)
            // stdcxx false

            // set the given ndk directory path (optional)
            // ndk "/Users/ruki/files/android-ndk-r20b/"

            // set sdk version of ndk (optional)
            // sdkver 21
        }
    }
}
</code></pre><h3 id="buildjniandgenerateapk">Build JNI and generate apk</h3>
<p>The <code>xmakeBuild</code> will be injected to <code>assemble</code> task automatically if the gradle-xmake-plugin has been applied.</p>
<pre><code class="lang-console">$ ./gradlew app:assembleDebug
> Task :nativelib:xmakeConfigureForArm64
> Task :nativelib:xmakeBuildForArm64
>> xmake build
[ 50%]: cache compiling.debug nativelib.cc
[ 75%]: linking.debug libnativelib.so
[100%]: build ok!
>> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/arm64-v8a
> Task :nativelib:xmakeConfigureForArmv7
> Task :nativelib:xmakeBuildForArmv7
>> xmake build
[ 50%]: cache compiling.debug nativelib.cc
[ 75%]: linking.debug libnativelib.so
[100%]: build ok!
>> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/armeabi-v7a
> Task :nativelib:preBuild
> Task :nativelib:assemble
> Task :app:assembleDebug
</code></pre>
<h3 id="forcetorebuildjni">Force to rebuild JNI</h3>
<pre><code class="lang-console">$ ./gradlew nativelib:xmakeRebuild
</code></pre>
</article>
</body>
</html>